﻿<?php
error_reporting(0);
define('IN_QY',true);
session_start();
require("include/common.inc.php");
require_once("include/config.php");
require_once("include/httpUtil.php");
define('SCRIPT','ad_list');

$total_fee=trim($_GET['total_fee']);

if($_GET['bill']!=""){
$infoid=$_GET['bill'];
$orderid =$_GET['bill'];		
}else{
	
$infoid=$_GET['out_trade_no'];
$orderid =$_GET['out_trade_no'];	
}

//
 $sql_user="select * from tbl_taorder where orderid='".$infoid."'  order by id desc  limit 1  " ;
 $queryuser=mysql_query($sql_user);
 $row=mysql_fetch_array($queryuser);


 //
 $sql3r="select * from tbl_taorder where orderid='".$infoid."' and (goodid=248 or goodid=134 or goodid=263 or goodid=223 or goodid=255 or goodid=179 or goodid=427 or goodid=470 or goodid=234 or goodid=260 or goodid=403 or goodid=262 or goodid=178 or goodid=425) " ;
 $query3r=mysql_query($sql3r);
 $row3=mysql_fetch_array($query3r);
 //
 
  $sqls="select * from tbl_taospp where  id='".$row['goodid']."'  order by id desc  limit 1  " ;
 $querys=mysql_query($sqls);
 $rows=mysql_fetch_array($querys);
 
 
 //
  $ff=$total_fee;
 $c=$row['uid'];
 
 if ($row['is_pay']==1) {
	echo "<script type='text/javascript'>alert('此订单已支付！');location.href='/wap/my.php';</script>";
    exit;
}
 
 
 //更新订单为已付款
 $sqlw = "update tbl_taorder set is_pay=1, paytime='".time()."' where orderid='".$orderid."'";
mysql_query($sqlw);

  /*********************写入账单**********************/
			$sqlu = "select * from tbl_user where id=".$row['uid'];
            $queryu=mysql_query($sqlu);
            $rowu=mysql_fetch_array($queryu);
            $jifen = $rowu['jifen'];
            $yuee = $rowu['yuee'];
            $xyf = $rowu['xyf'];
            $mobile = $rowu['userid'];
            $shuyu = $rowu['shuyu'];
			$is_vip = $rowu['is_vip'];
			
			$sqly = "insert into tbl_zhangdan values (0,'海淘付款','".$ff."','".$jifen."','".$xyf."',1,'".$yuee."','".date('Y-m-d H:i:s')."','".$row['uid']."','".$row['orderid']."',1,5)";
	             mysql_query($sqly);

 //短信发送开始--承租方
$funAndOperate = "industrySMS/sendSMS";
// 生成body
$body = createBasicAuthData();
// 在基本认证参数的基础上添加短信内容和发送目标号码的参数
$body['smsContent'] = '【众晒网】亲爱的'.$shuyu.'，您好！我们已经收到您订单'.$total_fee.'元的付款，我们会在第一时间为您配送发货，请耐心等待哦！';
$body['to'] = ''.$mobile.'';
$result = post($funAndOperate, $body);

/*********************加积分*********************/	

if($is_vip==1){

$jifen_fan=	$row['totprice'];
if($row3){

 $vip_fan=0;

}else {

 $vip_fan=	$row['totprice']*0.02;   
}


}else{
	
$jifen_fan=	$row['totprice']*0.5;
	


$vip_fan=0;

}

//积分+;返现
// $sqlyu = "update tbl_user set jifen=jifen+'".$jifen_fan."',cash_back=cash_back+'".$vip_fan."'  where id=".$c;
// mysql_query($sqlyu);

$sqlyu = "update tbl_user set jifen=jifen+'".$jifen_fan."' where id=".$c;
mysql_query($sqlyu);

//返现余额

$sql = "select jifen from tbl_user where id=".$c;
$query = mysql_query($sql);
$rowji = mysql_fetch_array($query);

$conten = "海淘送积分";
$sqltji = "insert into tbl_zhangdan values (0,'".$conten."','".$jifen_fan."','".$rowji['jifen']."',0,1,0,'".date("Y-m-d H:i:s")."','".$c."','".$orderid."',0,2)";
mysql_query($sqltji);


// if($vip_fan!=""){
	
// $sqly4 = "insert into tbl_zhangdan values (0,'海淘返现','".$vip_fan."','".$jifen."','".$xyf."',1,'".$yuee."','".date('Y-m-d H:i:s')."','".$row['uid']."','".$row['orderid']."',1,4)";
// mysql_query($sqly4);	

// }
//
 //积分开始发送
$funAndOperate = "affMarkSMS/sendSMS";
// 生成body
$body = createBasicAuthData();
// 在基本认证参数的基础上添加短信内容和发送目标号码的参数
$body['smsContent'] = '【众晒网】亲爱的'.$shuyu.'，您好！众晒网赠送您的'.$jifen_fan.'积分已经到账，详情可登录网站查询！点击：t.cn/EU52KGR 回t退订';
$body['to'] = ''.$mobile.'';
$result = post($funAndOperate, $body);
//积分开始发送


// if($vip_fan!=0){
	
 // //积分开始发送
// $funAndOperate = "affMarkSMS/sendSMS";
// // 生成body
// $body = createBasicAuthData();
// // 在基本认证参数的基础上添加短信内容和发送目标号码的参数
// $body['smsContent'] = '【众晒网】亲爱的'.$_COOKIE['shuyu'].'，您好！您有一笔'.$vip_fan.'元的返利已经到账。详情可登录网站查询！点击： t.cn/EU56SGi  回t退订';
// $body['to'] = ''.$mobile.'';
// $result = post($funAndOperate, $body);
// //积分开始发送	
	
// }

 $sql_userr="select * from tbl_taorder where orderid='".$infoid."'" ;
 $queryuserr=mysql_query($sql_userr);
   while ($rowr=mysql_fetch_array($queryuserr)) {

   
    $sql = "select id from tbl_taospp where (goodstype=2 or goodstype=3 ) and id='".$rowr['goodid']."'";
 $query = mysql_query($sql);
 $rowji = mysql_fetch_array($query);
   
   
 if($rowji){
 $sqlyu = "update tbl_taospp set state=0  where id='".$rowji['id']."'";
 mysql_query($sqlyu);
 }  


   }

//
//zouni 
if($rows['goodstype']<4){
	
echo "<script type='text/javascript'>alert('支付成功');location.href='/wap/my.php';</script>";	

}

?>






	<script type="text/javascript" src="/ui/xianzhi/js/jquery.min.js"></script>

    <script type="text/javascript" src="/ui/layer/mobile/layer.js"></script>  
	
	 <?php if($rows['goodstype']>3){ ?>
  	<script>

		var pay_type=2;
		var uid='<?=$_COOKIE['userid']?>';
		var goodsid='<?=$rows['id']?>';
		console.log(pay_type);
		console.log(uid);
		console.log(goodsid);		
	    $.ajax({
        url: '/api/muyin/api.php?s=user.pay_vip_use_score',
        type: 'POST',
        dataType: 'json',
        data: {goodsid: goodsid,
		uid:uid,
		pay_type:pay_type	
		},
      });

alert("支付成功");
	  
location.href='/wap/my.php';		

	


	
	</script>

		<?php }  ?>
